package com.briup.ch13;

import java.lang.reflect.Method;

/**
 * @author yuxi
 * @version 1.0
 * @date 2025/10/21
 * @Description:
 */
public class Test07 {
    public static void main(String[] args) throws NoSuchMethodException {
        Class clazz = Student.class;
        //获取public方法(包含继承的)
        Method[] methods = clazz.getMethods();
        for (Method method : methods) {
            if (method.getModifiers() == 1) {
                System.out.println(method.getName());
            }
        }
        System.out.println("=========" );
        //获得所有方法，包括public、private、protected、static、final等,不包含继承的，不包含Object类的方法，不包含构造方法
        Method[] allMethods = clazz.getDeclaredMethods();
        for (Method method : allMethods) {
            System.out.println(method.getName());
        }
        System.out.println("=========");
        //获得单个方法
        Method method = clazz.getDeclaredMethod("getAge");
        System.out.println(method.getName());
    }
}
